package com.aaron.messenger.util;

import android.content.Context;
import android.net.wifi.WifiInfo;
import android.net.wifi.WifiManager;
import android.telephony.TelephonyManager;

public class Utils {
	private static String sLocalIp = null;
	
	public static String getDeviceInfo(Context context) {
		TelephonyManager phone = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
		StringBuilder str = new StringBuilder();
		str.append("line1Number:"+phone.getLine1Number());
		str.append("simOperatorName:"+phone.getSimOperatorName());
		str.append("model"+android.os.Build.MODEL);
		
		WifiManager wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
		WifiInfo info = wifiManager.getConnectionInfo();
		str.append("mac:"+info.getMacAddress());
		
		return str.toString();
	}
	
	public static String getLocalIp(Context context) {
		WifiManager wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
		WifiInfo info = wifiManager.getConnectionInfo();
		int ip = info.getIpAddress();
		sLocalIp = (ip & 0xFF ) + "." + ((ip >> 8 ) & 0xFF) + "." + ((ip >> 16 ) & 0xFF) + "." + (ip >> 24 & 0xFF) ;
		return sLocalIp;
	}
	
	public static String peekLocalIp() {
		return sLocalIp;
	}

}
